package cn.it.hbtt.petoa.dao.impl;

import cn.it.hbtt.petoa.dao.BaseDAO;
import cn.it.hbtt.petoa.dao.PetOwnerDAO;
import cn.it.hbtt.petoa.entity.Pet;
import cn.it.hbtt.petoa.entity.PetOwner;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author John
 * @create 2020-06-04 11:23
 */
public class PetOwnerDAOImpl implements PetOwnerDAO {

    /**
     * 用户登录的功能
     * @param owner  登录人对象，保存着登录人的账号密码
     * @return
     */
    public PetOwner login(PetOwner owner) {

        try {
            Connection conn = BaseDAO.getConnection();

            String sql="SELECT * FROM  petowner WHERE name = ? and password= ?";

            PreparedStatement pstm  = conn.prepareStatement(sql);

            pstm.setObject(1,owner.getName());
            pstm.setObject(2,owner.getPassword());
            ResultSet rs = pstm.executeQuery();

           if(rs.next()){
               PetOwner petOwner = new PetOwner();
               petOwner.setId(rs.getInt(1));
               petOwner.setName(rs.getString("name"));
               petOwner.setPassword(rs.getString("password"));
               petOwner.setMoney(rs.getInt("money"));
               return petOwner;
           }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<PetOwner> getAll() {
        return null;
    }

    public List<Pet> getAllByObject() {
        return null;
    }

    public int login(String name, String pwd) {
        return 0;
    }

    public ResultSet findByMonster(PetOwner owner) {
        return null;
    }

    public int findOwnerid(PetOwner owner) {
        return 0;
    }

    public void sell(Pet pet) {

    }
}
